package com.myapp.api.mapper;

import com.myapp.api.entity.Dept;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface DeptMapper {
    @Delete({
        "delete from dept",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into dept (id, Did, ",
        "Dname, Dinfo, CreateTime, ",
        "UpdateTime)",
            "values (#{id,jdbcType=INTEGER}, #{did,jdbcType=VARCHAR}, ",
        "#{dname,jdbcType=VARCHAR}, #{dinfo,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, ",
        "#{updatetime,jdbcType=TIMESTAMP})"
    })
    int insert(Dept record);

    @InsertProvider(type=DeptSqlProvider.class, method="insertSelective")
    int insertSelective(Dept record);

    @Select({
        "select",
        "id, Did, Dname, Dinfo, CreateTime, UpdateTime",
        "from dept",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
        @Result(column="Dname", property="dname", jdbcType=JdbcType.VARCHAR),
        @Result(column="Dinfo", property="dinfo", jdbcType=JdbcType.VARCHAR),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    Dept selectByPrimaryKey(Integer id);

    @UpdateProvider(type=DeptSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Dept record);

    @Update({
        "update dept",
            "set Did = #{did,jdbcType=VARCHAR},",
          "Dname = #{dname,jdbcType=VARCHAR},",
          "Dinfo = #{dinfo,jdbcType=VARCHAR},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Dept record);

    @Select({
            "select",
            "id, Did, Dname, Dinfo, CreateTime, UpdateTime",
            "from dept"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
            @Result(column="Dname", property="dname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Dinfo", property="dinfo", jdbcType=JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Dept> getDepts();

    @Select({
            "select",
            "id, Did, Dname, Dinfo, CreateTime, UpdateTime",
            "from dept",
            "where Did = #{did,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
            @Result(column="Dname", property="dname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Dinfo", property="dinfo", jdbcType=JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    Dept getDeptByDid(String did);

    @Select({
            "select count(*)",
            "id, Did, Dname, Dinfo, CreateTime, UpdateTime",
            "from dept",
            "where Did = #{did,jdbcType=VARCHAR}"
    })
    Integer getDeptByOneDid(String did);

    @Select({
            "select",
            "id, Did, Dname, Dinfo, CreateTime, UpdateTime",
            "from dept",
            "where Dname like concat('%',#{dname,jdbcType=VARCHAR},'%')"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Did", property = "did", jdbcType = JdbcType.VARCHAR),
            @Result(column="Dname", property="dname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Dinfo", property="dinfo", jdbcType=JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UpdateTime", property="updatetime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Dept> getDeptByDname(String dname);
}